![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@cloudflare/workers-types
Advanced tools
@cloudflare/workers-types provides TypeScript type definitions for Cloudflare Workers, enabling developers to write type-safe code for Cloudflare's serverless platform.
FetchEvent
The FetchEvent interface represents the event that is fired when a Fetch request is made. This allows you to intercept and handle HTTP requests.
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request: Request): Promise<Response> {
return new Response('Hello, world!');
}
KVNamespace
KVNamespace provides type definitions for Cloudflare Workers KV, a key-value storage system. This allows you to interact with KV storage in a type-safe manner.
declare const MY_KV_NAMESPACE: KVNamespace;
async function handleRequest(request: Request): Promise<Response> {
const value = await MY_KV_NAMESPACE.get('my-key');
return new Response(value || 'Key not found');
}
DurableObjectNamespace
DurableObjectNamespace provides type definitions for Durable Objects, which are stateful objects that can be used to manage state across multiple requests.
declare const MY_DURABLE_OBJECT_NAMESPACE: DurableObjectNamespace;
class MyDurableObject {
state: DurableObjectState;
constructor(state: DurableObjectState) {
this.state = state;
}
async fetch(request: Request): Promise<Response> {
return new Response('Durable Object response');
}
}
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request: Request): Promise<Response> {
const id = MY_DURABLE_OBJECT_NAMESPACE.idFromName('object-name');
const stub = MY_DURABLE_OBJECT_NAMESPACE.get(id);
return stub.fetch(request);
}
@types/aws-lambda provides TypeScript type definitions for AWS Lambda, another serverless computing platform. While it offers type safety for AWS Lambda functions, it does not cover Cloudflare-specific features.
@types/express provides TypeScript type definitions for Express.js, a web application framework for Node.js. While it helps in building server-side applications, it does not offer the serverless and edge computing capabilities of Cloudflare Workers.
npm install @cloudflare/workers-types
-- Or
yarn add @cloudflare/workers-types
The following is a minimal tsconfig.json
for use alongside this package:
tsconfig.json
{
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"lib": ["ES2020", "WebWorker"],
"types": ["@cloudflare/workers-types"]
}
}
It's recommended that you create an ambient type file for any bindings your Worker uses. Create a file named bindings.d.ts
in your src directory:
bindings.d.ts
export {};
declare global {
const MY_ENV_VAR: string
const MY_SECRET: string
const myKVNamespace: KVNamespace
}
FAQs
TypeScript typings for Cloudflare Workers
The npm package @cloudflare/workers-types receives a total of 339,007 weekly downloads. As such, @cloudflare/workers-types popularity was classified as popular.
We found that @cloudflare/workers-types demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 35 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.